package com.itheima.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.SportsLibraryDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.SportsLibrary;

import javax.annotation.Resource;

/**
 * 检查项CRUD操作业务实现类
 * @author W.J.Y
 */
@Service(version = "1.0.0",interfaceClass = SportsLibraryService.class)

public class SportsLibraryServiceimpl implements SportsLibraryService {

    @Resource
    private SportsLibraryDao sportsLibraryDao;


    @Override
    public PageResult findPage(int pageNum, int pageSize, String queryString) {
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        //调用dao层查询语句
        Page page = sportsLibraryDao.findPage(queryString);
        //封装分页查询结果对象
        return new PageResult(page.getTotal(),page.getResult());
    }



    @Override
    public Result add(SportsLibrary sportsLibrary) {
        sportsLibraryDao.add(sportsLibrary);
        return null;

    }

    @Override
    public void delete(int id) {
        sportsLibraryDao.delete(id);

    }



    @Override
    public void update(SportsLibrary sportsLibrary) {
        sportsLibraryDao.update(sportsLibrary);
    }




    /*@Resource
    private CheckItemDao checkItemDao;

    *//**
     * 新增检查项
     * @param checkItem 检查项实例
     *//*
    @Override
    public void add(CheckItem checkItem) throws BusinessException {
        Integer count = checkItemDao.findByNameOrCode(checkItem);
        if(count>0){
            throw new RuntimeException("已存在同名或者同编号的检查项，添加失败！");
        }
        checkItemDao.add(checkItem);
    }

    *//**
     * 编辑检查项
     * @param checkItem 检查项实例
     *//*
    @Override
    public void update(CheckItem checkItem) throws BusinessException {
        Integer count = checkItemDao.findByNameOrCode(checkItem);
        if(count>0){
            throw new RuntimeException("已存在同名或者同编号的检查项，编辑失败！");
        }
        checkItemDao.update(checkItem);
    }

    *//**
     * 删除检查项
     * @param id 检查项ID
     *//*
    @Override
    public void delete(int id) throws BusinessException {
        //查询该检查项是否被检查组使用
        int count = checkItemDao.countByIdFromCheckgroup(id);
        if (count>0){
            throw new RuntimeException("该检查项已被检查组占用，删除失败！");
        }
        checkItemDao.delete(id);
    }

    *//**
     * 分页查询
     * @param pageNum  查询页码
     * @param pageSize  每页显示条数
     * @param queryString   检查项编号或者名称
     * @return  分页查询返回结果
     *//*
    @Override
    public PageResult findPage(int pageNum, int pageSize, String queryString) {
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        //调用dao层查询语句
        Page page = checkItemDao.findPage(queryString);
        //封装分页查询结果对象
        return new PageResult(page.getTotal(),page.getResult());
    }

    *//**
     * 查询所有的检查项
     * @return  检查项列表
     *//*
    @Override
    public List<CheckItem> findAll(){
        return checkItemDao.findAll();
    }*/
}
